import axios from 'axios'
export default value => {
  let path = `/api/book-content/modules/article/waps.php?keyword=${value}`
  return axios.get(path)
    .then(response => {
      let data = response.data.match(/<p class="line">.*<\/p>/g, '')
      if (!data) {
        return []
      }
      let booklist = []
      // 遍历带html标签的搜索结果
      for (let i = 0; i < data.length; i++) {
        let bookInfo = {
          title: '',
          author: '',
          id: 0
        }
        bookInfo.title = data[i]
          .match(/<a href="\/info-.*\/" class="blue">.*<\/a>/g, '')
          .join('')
          .replace(/<a href="\/info-.*\/" class="blue">/g, '')
          .replace(/<\/a>\/<a href="\/author\/.*">.*<\/a>/g, '')
        bookInfo.author = data[i]
          .match(/<a href="\/author\/.*">.*<\/a>/g, '')
          .join('')
          .replace(/<a href="\/author\/.*">/g, '')
          .replace(/<\/a>/g, '')
        bookInfo.id = data[i]
          .match(/<a href=".*" class="blue">/g, '')
          .join('')
          .replace(/<a href="\/sort-.*\/">.*<\/a><a href="\/info-/g, '')
          .replace(/\/" class="blue">/g, '')
        booklist.push(bookInfo)
      }
      return booklist
    })
}
